package com.drojian.singleton.type4;

import org.junit.Test;

/**
 * 懒汉式（线程安全）加了同步代码块，效率低
 */
public class SingletonTest04 {
    @Test
    public void test01(){
        Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance == instance2);
    }
}


class Singleton{
    private  static Singleton instance;
    public Singleton() {
    }
    public static synchronized Singleton getInstance() {
        if(instance == null){
            instance =  new Singleton();
        }
        return instance;
    }
}